$(function () {
    wowInt();
    findTel();
    phoneTargetSelf();
    nav();
    myhome();
    sidebar();
    ind02_sw();

    /*返回顶部*/
    $(".back_top").click(function(){
        $("html,body").stop().animate({scrollTop:0});
    })
    $(window).scroll(function(){
        if($(window).scrollTop()>0){
            $(".back_top").show().stop().animate({"opacity":1});
        }else{
            $(".back_top").stop().animate({"opacity":1},function(){
                $(".back_top").hide();
                // $('.sidebar').addClass('off');
            });
        }
    })

    //微信公众号
    $(".wechat").click(function () {
        var url=$(this).data("img")
        var title=""
        title+="<div class='weixin-box'>"
        title+="<i class='c'>x</i>"
        title+="<h2>微信公众号</h2>"
        title+="<div class='img'><img src='"+ url +"' width='100px;' height='100px;'></div>"
        title+="<p>扫一扫关注公众号</p>"
        title+="</div>"
        $("body").remove(".weixin");
        $("body").append(title);
    })
    $(document).on("click",".weixin-box .c",function(){
        $(".weixin-box").remove();
    })
    //end


    //顶部悬浮
    $(window).scroll(function(){
        $(".head_bot .myhome dd").slideUp();
        if($(window).scrollTop()>0){
            $("body").addClass("scroll-header");
        }else{
            $("body").removeClass("scroll-header");
        }
    })
    //end
    
  
   
    //公共选项卡
    $(".tab-box .tab-a").each(function() {
        $(this).click(function() {
            if (!$(this).hasClass("off")) {
                $(this).addClass("on").siblings().removeClass("on");
                var ii=$(this).index();
                $(this).parents(".tab-box").find(".tab-b").eq(ii).show().siblings().hide();
            }
        });   
    })
    $(".tab-box").each(function (i) {
        $(this).find(".tab-a:eq(0)").click();
    });
    //end

    //首页精品门切换
    $(document).on('click','.rr_txt li',function(){
        $(this).addClass("on").siblings().removeClass("on");
        var url = $(this).data("src");
        if(url == ""){
            return false;
        }else{
            commAjax(".ll_img",url);
        }
    })
    $(".rr_txt li:eq(0)").click();


    //首页会员福利3张图切换
    $(document).on('click','.slide .slide_bot li',function(){
        var ind = $(this).index();
        $(this).addClass("on").siblings().removeClass("on");
        $(this).parents(".slide").find(".slide_top").find("li").eq(ind).show().siblings().hide();
    })
    $(".slide_bot li:eq(0)").click();


    //首页初始弹窗关闭
    $(document).on('click','.tbox01 .close',function(){
        $(".lay-bg").fadeOut();
        $(this).parents(".tbox01").fadeOut();
    })
    $(document).on('click','.tbox01 .btn01',function(){
        $(".lay-bg").fadeOut();
        $(this).parents(".tbox01").fadeOut();
    })

    //首页右下角浮层
    $(document).on('click','.show_bot',function(){
        $('.bot_cons').show();
		$('.bot_cons').stop().animate({bottom:"0"},700);
		$(this).hide();
    })
    $(document).on('click','.bot_cons .close',function(){
        $(this).parents('.bot_cons').fadeOut(function(){
			$(this).css({bottom:"-170px"});
		})
		$('.show_bot').fadeIn();
    })

    
    



    
  
    
})

//sidebar
function sidebar() {
    $(window).scroll(function(){
        if($(this).scrollTop() >= 200){
            $('.sidebar').fadeIn();
        }else{
            $('.sidebar').fadeOut();
        }
    })
    $('.sidebar .sidebar-close').click(function(e){
        e.stopPropagation();
        $('.sidebar').addClass('off');
    })
    
    $('.sidebar').hover(function(){
        $(this).removeClass('off');
    },function(){})
    
    if($(this).width() < 1025){
        /*if (/(Android)/i.test(navigator.userAgent)){
            $('.sidebar').addClass('out');
        }*/
        $('.sidebar').addClass('off');
        $('.sidebar.off').click(function(){
            $(this).removeClass('off');
        })
    }
    }
    window.onload = function(){
        setTimeout(function(){
            $(window).scroll();
        },300)
    }
//end

function ind02_sw(){
    var ind02_sw = new Swiper('.index-part02 .swiper-container',{
        slidesPerView : 3,//'auto'
        spaceBetween : 20,
        prevButton:'.index-part02 .swiper-button-prev',
        nextButton:'.index-part02 .swiper-button-next',
    })
}



function ind04_sw(){
    var ind04_sw = new Swiper('.indp04_img .swiper-container',{
        prevButton:'.indp04_img .swiper-button-prev',
        nextButton:'.indp04_img .swiper-button-next',
    })
}



function commAjax(str,url){
	$.ajax({
		url:url,
		success:function(msg){
			$(str).html("");
            $(str).append(msg);
		}
	});
}

//主导航
function nav(){
    if($(window).width()>1024){        
        $(".nav ul>li").hover(function() {
            $(this).find(".navlist").stop().slideDown();
        }, function() {
            $(this).find(".navlist").stop().slideUp();
        });
    }else{
        $(".navlist").siblings("span").addClass("cur");
        $(document).on('click','.nav_phone_btn',function(e){
            e.preventDefault();
            e.stopPropagation();
            $('.nav_phone_btn').toggleClass('visible_nav');
            $('body').toggleClass('body_nav_phone'); 
            $(".nav_click").show();
        });

       
        $(document).on('click','.nav_click',function(){       
            $('.nav_phone_btn').removeClass('visible_nav');
            $('body').removeClass('body_nav_phone'); 
            $(this).hide();
        })
        $(document).on('click','.nav ul li span',function(e){
            $(this).parent("li").siblings().find("span").removeClass("on");
            $(this).parent("li").siblings().find(".navlist").slideUp();
            $(this).toggleClass("on");
            $(this).siblings(".navlist").slideToggle();
        })
    }
}

//导航左侧我的家分类
function myhome(){
    $(document).on('click','.myhome dt',function(e){
        e.preventDefault();
        e.stopPropagation();
        $(".myhome dd").slideToggle(200);
    })
    $(document).click(function(){           
        $(".myhome dd").slideUp(200);
    })
}


// 地图
function mapInt(mapTitle,mapAdress,mapx,mapy){
    var num = 0.0011;
    var map = new BMap.Map("map");
    var point = new BMap.Point(mapx-num,mapy);
    var point2 = new BMap.Point(mapx,mapy);

    var myIcon = new BMap.Icon("../images/conn_map.png", new BMap.Size(40,47));// icon按钮
    var marker2 = new BMap.Marker(point2,{icon:myIcon});  // 创建标注
    map.addOverlay(marker2);              // 将标注添加到地图中
    map.centerAndZoom(point, 19);
    if($(window).width()<1024){
        num = 0;
        map.centerAndZoom(point2, 19);
    }
     /*var opts = {
            width : 200,     
            height: 100,    
            title : "胜利油田大明集团"
          }
          var infoWindow = new BMap.InfoWindow("地址：山东省东营市东营区千佛山路20号", opts);  // 创建信息窗口对象 
          marker2.addEventListener("click", function(){          
          map.openInfoWindow(infoWindow,point2); //开启信息窗口
          });*/
    map.enableScrollWheelZoom();   //启用滚轮放大缩小，默认禁用
    map.enableContinuousZoom();    //启用地图惯性拖拽，默认禁用 
}


//--------------点击分享
function share(){
    /*
    $(".share_in").click(function () {//linkedin
        var url = $(this).data("txt");
        var url = window.location.href;
        var title = document.title;
        var op = "//www.linkedin.com/uas/login?title=" + title + "&url=" + encodeURIComponent(url) + "";
        window.open(op);
    })
    $(".share_bdtb").click(function () {//百度贴吧
        var url = $(this).data("txt");
        var url = window.location.href;
        var title = document.title;
        var op = "http://tieba.baidu.com/f/commit/share/openShareApi?title=" + title + "&url=" + encodeURIComponent(url) + "";
        window.open(op);
    })
    $(".share_qqkj").click(function () {//腾讯微博
            var url = $(this).data("txt");
            var url = window.location.href;
            var title = document.title;
            var op = "https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?title=" + title + "&url=" + encodeURIComponent(url) + "";
            window.open(op)
    })
    $(".share_douban").click(function () {//豆瓣
        var url = $(this).data("txt");
        var url = window.location.href;
        var title = document.title;
        var op = "https://www.douban.com/share/service?title=" + title + "&url=" + encodeURIComponent(url) + "";
        window.open(op);
    })*/

    $(".share_wb").click(function () {//微博
        var url = $(this).data("txt");
        var url = window.location.href;
        var title = document.title;
        var op = "http://service.weibo.com/share/share.php?title=" + title + "&url=" + encodeURIComponent(url) + "";
        window.open(op)
    })
    $(".share_qq").click(function () {//QQ
        var url = $(this).data("txt");
        var url = window.location.href;
        var title = document.title;
        var op = "http://connect.qq.com/widget/shareqq/index.html?url=" + encodeURIComponent(url) + "";
        window.open(op);
    })
    //微信
    $(".share_wx").attr("data-qrcode","http://www.xinhongru.com/qrcode/qrcode.php?content="+window.location.href); 
    //$(".share_wx").attr("data-qrcode", "/qrCode/Index.aspx?url=" + window.location.href);
   
    $(".share_wx").click(function () {//微信
		//var url = "/qrCode/Index.aspx?url=" + window.location.href;
		var url = $(this).attr("data-qrcode")
        console.log(url)
        var title = ""
        title += "<div class='weixin'>"
        title += "<i class='c'>x</i>"
        title += "<h2>二维码</h2>"
        title += "<div class='img'><img src='" + url + "' width='100px;' height='100px;'></div>"
        title += "<p>扫一扫</p>"
        title += "</div>"
        $("body").remove(".weixin");
        $("body").append(title)
    })
    $(document).on("click", ".weixin .c", function () {
        $(".weixin").remove();
    })
}



//public_ajax
function public_ajax() {
    if($(".ajLoad").length>0){
        var $resourceTypeList = $('.ajLoad ul');        
        $resourceTypeList.infinitescroll({
            navSelector: "#public_more",
            nextSelector: "#public_more a",
            itemSelector: ".public_li",
            clickb: true,
            clickobj: ".public_load-more-link",
            loading: {
                img: "../images/loading.gif",
                msgText: ' ',
                finishedMsg: '',
                finished: function() {
                    $("#infscr-loading").hide();
                    imgratio();
                }
            },
            errorCallback: function() {
                $(".public_load-more-link").after("<div class='finMessage' style='background:rgba(0,0,0,0.4); position:fixed; width:100px; height:50px; line-height:50px;overflow:hidden; border-radius:10px; text-align:center; color:#fff; left:50%; top:50%; z-index:1000; margin:-15px 0 0 -50px;'>没有了</div>");
                $(".public_load-more-link").hide();
                setTimeout(function () {
                    $(".finMessage").fadeOut();
                }, 500)
            }
        }, function(newElements) {
            var $newElems = $(newElements);
            $newElems.fadeIn();
            return;
        });
    }
}


function GetQueryString(parm) {
    var reg = new RegExp("(^|&)"+ parm +"=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    //console.log(r);//["&name=222", "&", "222", "", index: 4, input: "id=1&name=222"]
    if(r!=null) {
		return  unescape(r[2]); 
	} else {
		return null;
	}
}

//wow入场
function wowInt(){
    if (!(/msie [6|7|8|9]/i.test(navigator.userAgent))){
        var wow = new WOW({
            boxClass: 'wow',
            animateClass: 'animated',
            offset: -100,
            mobile: true,
            live: true
        });
        wow.init();
    };
}

/*手机端链接改为本窗口打开*/
function phoneTargetSelf(context){  
    if ($(window).width()<1024) {
      if(context==undefined){
        context=$(document);
      }
      $('a',context).each(function(){
        var target=$(this);
        var link=target.attr('target');
        target.attr('target','_self');
      })
    }
}
  
  
/*电话链接取消默认事件并添加样式*/
function findTel(context){
    if ($(window).width()>1024) {
        var condition = /^tel\:([0-9\-]+)|tel\:\+([0-9\-]+)$/;
        if(context==undefined){
        context=$(document);
        }
        $('a',context).each(function(index, el) {
        var target=$(this);
        var href=target.attr('href');
        if (condition.test(href)) {
            target.addClass('tel_link');
            target.on('click',function(event){
            event.preventDefault();
            })
        }
        });
    }
}



/*ie9的placeholder包含密码框的兼容*/
$(function(){
    if(!placeholderSupport()){   // 判断浏览器是否支持 placeholder        
        $('input').not("input[type='password']").each(
            function() {
                var self = $(this);
                var val = self.attr("placeholder");
                input(self, val);
                /*if($(this).val()=="" && $(this).attr("placeholder")!=""){
                    $(this).val($(this).attr("placeholder"));
                    $(this).focus(function(){
                        if($(this).val()==$(this).attr("placeholder")) $(this).val("");
                    });
                    $(this).blur(function(){
                        if($(this).val()=="") $(this).val($(this).attr("placeholder"));
                    });
                }*/
            }
        );
        $('input[type="password"]').each(
            function() {
                var pwdField    = $(this);
                var pwdVal      = pwdField.attr('placeholder');
                var pwdClass       = pwdField.attr('class');
                // 重命名该input的id为原id后跟1
                pwdField.after('<input class="login-input" type="text" value='+pwdVal+' autocomplete="off" />');
                var pwdPlaceholder = $(this).siblings('.login-input');
                pwdPlaceholder.show();
                pwdField.hide();

                pwdPlaceholder.focus(function(){
                    pwdPlaceholder.hide();
                    pwdField.show();
                    pwdField.focus();
                });

                pwdField.blur(function(){
                    if(pwdField.val() == '') {
                        pwdPlaceholder.show();
                        pwdField.hide();
                    }
                });
            }
        );

    };
})

// 判断浏览器是否支持placeholder属性
function placeholderSupport() {
    return 'placeholder' in document.createElement('input');
}
// jQuery替换placeholder的处理
function input(obj, val) {
    var $input = obj;
    var val = val;
    $input.attr({value:val});
    $input.focus(function() {
        if ($input.val() == val) {
            $(this).attr({value:""});
        }
    }).blur(function() {
        if ($input.val() == "") {
            $(this).attr({value:val});
        }
    });
}
//end


$(function(){
    AppointRuler();

    var windowTop = 0;//初始话可视区域距离页面顶端的距离
    $(window).scroll(function () {
       
        var scrolls = $(this).scrollTop();//获取当前可视区域距离页面顶端的距离
        if (scrolls >= windowTop) {//当B>A时，表示页面在向下滑动
            $("body").removeClass("edit_header02");
            windowTop = scrolls;
        } else {//当B
            $("body").addClass("edit_header02");
            windowTop = scrolls;
        }
    });
    
})
function AppointRuler(){
    $(document).on("click",".ruler_btn",function(){
        $("body").addClass("nocsoll");
        $(".appoint_blakn60,.appoint_ruler").stop().fadeIn();
    })
    $(document).on("click",".appoint_close",function(){
        $("body").removeClass("nocsoll");
        $(".appoint_blakn60,.appoint_ruler").stop().fadeOut();
    })
}







